package com.honghe.system.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.honghe.common.core.controller.BaseController;
import com.honghe.common.core.domain.AjaxResult;
import com.honghe.common.core.domain.model.LoginUser;
import com.honghe.common.utils.SecurityUtils;
import com.honghe.system.domain.SysCaseAssign;
import com.honghe.system.service.ISysCaseAssignService;

/**
 * 案件分配关系Controller
 */
@RestController
@RequestMapping("/system/cases")
public class SysCaseAssignController extends BaseController
{
    @Autowired
    private ISysCaseAssignService sysCaseAssignService;

    /**
     * 分配案件
     */
    @PreAuthorize("@ss.hasPermi('system:cases:assign')")
    @PostMapping("/assign")
    public AjaxResult assign(@RequestBody SysCaseAssign sysCaseAssign)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        sysCaseAssign.setCreateBy(loginUser.getUsername());
        return toAjax(sysCaseAssignService.insertCaseAssign(sysCaseAssign));
    }

    /**
     * 查询案件分配关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:cases:list')")
    @GetMapping("/assign/list/{caseId}")
    public AjaxResult list(@PathVariable("caseId") Long caseId)
    {
        List<SysCaseAssign> list = sysCaseAssignService.selectCaseAssignList(caseId);
        return success(list);
    }

    /**
     * 删除案件分配关系
     */
    @PreAuthorize("@ss.hasPermi('system:cases:assign')")
    @DeleteMapping("/assign/{caseId}")
    public AjaxResult remove(@PathVariable Long caseId)
    {
        return toAjax(sysCaseAssignService.deleteCaseAssignByCaseId(caseId));
    }
} 